{% extends "djips/common/base.html" %}
{% load i18n %}

{% block title %}
{% trans "Manage installed languages" %}
{% endblock %}

{% block content %}
{% if not values %}
  <p>{% trans "No languages installed." %}</p>
{% endif %}

{% if update_errors %}
  <p class="error_msg">{% trans "Errors have been found while trying to save
  languages, correct them before submitting." %}</p>
{% endif %}

{% if add_errors %}
  <p class="error_msg">{% trans "Errors have been found while trying to add the
  new language, correct them before submitting." %}</p>
{% endif %}

{% if success %}
  <p class="info_msg">{% trans "Languages have been saved." %}</p>
{% endif %}

{% if no_sync %}
  <p class="error_msg">{% trans "Please synchronize file system
    before." %}</p>
{% else %}

<form name="update_languages"
      action="{{admin_base_url}}/djips_common/languages/"
      method="POST">
  <table class="listing">
    <thead>
      <tr>
	<th>{% trans "Default language" %}</th>
	<th>{% trans "Code" %}</th>
	<th>{% trans "Name" %}</th>
	<th>{% trans "Activated" %}</th>
      </tr>
    </thead>
    <tbody>
      {% for lang in values %}
      <tr class="{% if forloop.counter|divisibleby:2 %}even{% else %}odd{% endif %}">
	<td>
	  <input type="radio"
	         name="default"
	         {% if lang.default %}checked="checked"{% endif %}
	         value="{{lang.id}}" />
	</td>
	<td>
	  {{lang.id}}
	</td>
	<td>
	  {% if lang.empty_name %}
	  <p class="error_msg">{% trans "Name can not be empty." %}</p>
	  {% endif %}

	  {% if lang.too_long_name %}
	  <p class="error_msg">{% trans "This name is too long (50 characters
	  maximum)." %}</p>
	  {% endif %}
	  <input type="text"
	         name="name_{{lang.id}}"
	         value="{{lang.name}}" />
	</td>
	<td>
	  <input type="checkbox"
	         {% if lang.activated %}checked="checked"{% endif %}
	         name="activated_{{lang.id}}" />
	</td>
      </tr>
      {% endfor %}
      <tr class="separator">
	<td colspan="4">{% trans "Add new language" %}</td>
      </tr>
      <tr>
      	<td>
	  <input type="radio"
	         name="default"
	         {% if not values %}checked="checked"{% endif %}
	         value="new_lang" />
	</td>
	<td>
	  {% if new.used_id %}
	  <p class="error_msg">{% trans "This code is already used." %}</p>
	  {% endif %}
	  
	  {% if new.empty_id %}
	  <p class="error_msg">{% trans "Code can not be empty." %}</p>
	  {% endif %}

	  {% if new.too_long_id %}
	  <p class="error_msg">{% trans "This code is too long (5 characters
	  maximum)." %}</p>
	  {% endif %}
	  
	  <input type="text"
	         name="new_id"
	         maxlength="5"
	         value="{{new.id}}" />
	</td>
	<td>
	  {% if new.empty_name %}
	  <p class="error_msg">{% trans "Name can not be empty." %}</p>
	  {% endif %}

	  {% if new.too_long_name %}
	  <p class="error_msg">{% trans "This name is too long (50 characters
	  maximum)." %}</p>
	  {% endif %}
	  
	  <input type="text"
	         name="new_name"
	         value="{{new.name}}" />
	</td>
	<td>
	  <input type="checkbox"
	         {% if new.activated %}checked="checked"{% endif %}
	         name="activated_new" />
	</td>
      </tr>
    </tbody>
  </table>

 <div class="center">
   <input type="submit"
          class="valid"
          name="save"
          value="{% trans "Update languages" %}"/>
   <input type="submit"
          class="cancel"
          name="cancel"
          value="{% trans "Cancel" %}"/>
  </div>
</form>
{% endif %}
{% endblock%}
